package cn.com.backstage.controller.base;

import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Date;
import java.text.SimpleDateFormat;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import cn.com.api.entity.ApiU_user_friend_setting;

import cn.com.api.service.ApiU_user_friend_settingService;

import cn.com.util.*;


public class U_user_friend_settingBaseController {

	private static Logger logger = Logger.getLogger(U_user_friend_settingBaseController.class);
	
	@Autowired
	private ApiU_user_friend_settingService apiU_user_friend_settingService;
	
	/**
	 * 列表
	 * @return
	 */
	@RequestMapping(value = "u_user_friend_setting-list")
	public ModelAndView u_user_friend_setting_list(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = new ModelAndView("forward:/backstage/u_user_friend_setting_list.jsp");
		
		List<ApiU_user_friend_setting> u_user_friend_settings = apiU_user_friend_settingService.findU_user_friend_settings();
		mv.addObject("u_user_friend_settings", u_user_friend_settings);
		
		return mv;
	}
	
	/**
	 * 进入新增或者编辑页面
	 * @return
	 */
	@RequestMapping(value = "u_user_friend_setting-add-pre")
	public ModelAndView u_user_friend_setting_add_pre(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = new ModelAndView("forward:/backstage/u_user_friend_setting_add.jsp");
		//
		if(request.getParameter("id")!=null){
			String id = request.getParameter("id");
			ApiU_user_friend_setting u_user_friend_setting = apiU_user_friend_settingService.findU_user_friend_settingById(Integer.valueOf(id));
			mv.addObject("u_user_friend_setting",u_user_friend_setting);
		}
		return mv;
	}

	/**
	 *新增或者编辑
	 * @return
	 */
	@RequestMapping(value = "u_user_friend_setting-add")
	public void u_user_friend_setting_add(HttpServletRequest request, HttpServletResponse response) throws Exception{
		String id = request.getParameter("id");
		String user_id = request.getParameter("user_id");
		String is_open = request.getParameter("is_open");
		String type = request.getParameter("type");
		String is_top = request.getParameter("is_top");
		String is_nointerrupt = request.getParameter("is_nointerrupt");
		String is_neglectnoread = request.getParameter("is_neglectnoread");
		String is_senddel = request.getParameter("is_senddel");
		String is_receivedel = request.getParameter("is_receivedel");
		
		Map<String,Object> map = new HashMap<String,Object>();
		//String id = request.getParameter("id");
		//add
		if(id==null || (id.trim()).equals("")){
			ApiU_user_friend_setting u_user_friend_setting = new ApiU_user_friend_setting();
            /*
		    u_user_friend_setting.setId(id);
		    u_user_friend_setting.setUser_id(user_id);
		    u_user_friend_setting.setIs_open(is_open);
		    u_user_friend_setting.setType(type);
		    u_user_friend_setting.setIs_top(is_top);
		    u_user_friend_setting.setIs_nointerrupt(is_nointerrupt);
		    u_user_friend_setting.setIs_neglectnoread(is_neglectnoread);
		    u_user_friend_setting.setIs_senddel(is_senddel);
		    u_user_friend_setting.setIs_receivedel(is_receivedel);
	        */
			apiU_user_friend_settingService.insertU_user_friend_setting(u_user_friend_setting);
		}
		//edit
		else{
			ApiU_user_friend_setting u_user_friend_setting = apiU_user_friend_settingService.findU_user_friend_settingById(Integer.valueOf(id));
	        /*
		    u_user_friend_setting.setId(id);
		    u_user_friend_setting.setUser_id(user_id);
		    u_user_friend_setting.setIs_open(is_open);
		    u_user_friend_setting.setType(type);
		    u_user_friend_setting.setIs_top(is_top);
		    u_user_friend_setting.setIs_nointerrupt(is_nointerrupt);
		    u_user_friend_setting.setIs_neglectnoread(is_neglectnoread);
		    u_user_friend_setting.setIs_senddel(is_senddel);
		    u_user_friend_setting.setIs_receivedel(is_receivedel);
			*/
			apiU_user_friend_settingService.updateU_user_friend_setting(u_user_friend_setting);
		}
		//
		map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
		map.put(Utils.MESSAGE, "添加成功！");
        JsonUtil.printJson(response, JsonUtil.object2json(map));
	}
	
	/**
	 *删除
	 * @return
	 */
	@RequestMapping(value = "u_user_friend_setting-delete")
	public void u_user_friend_setting_delete(HttpServletRequest request, HttpServletResponse response) throws Exception{
		
		Map<String,Object> map = new HashMap<String,Object>();
		String id = request.getParameter("id");
		
		//delete
		int ret_i =	apiU_user_friend_settingService.deleteU_user_friend_setting(Integer.valueOf(id));
		
		//
		if(ret_i > 0){
			map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
			map.put(Utils.MESSAGE, "删除成功！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}
	
}



